#include <iostream>
#include <vector>
using namespace std;

struct Node
{
	bool arrival;
	int prev;
	int track;

	Node()
	{
		arrival = false;
		prev = -1;
	}
};

int main()
{
	while(true)
	{
		int N = 0;
		if( !(cin >> N ) )
		{
			break;
		}
		int count = 0;
		cin >> count;
		vector<int> tracks( count );
		for( int i = 0; i < count; i++ )
		{
			cin >> tracks[i];
		}

		vector<Node> F( N + 1 );
		F[0].arrival = true;
		int max = 0;

		for( int i = 0; i < count; i++ )
		{
			for( int j = max; j >= 0; j-- )
			{
				if( F[j].arrival )
				{
					int k = j + tracks[i];
					if( k > N ) continue;
					if( F[k].arrival ) continue;
					F[k].arrival = true;
					F[k].prev = j;
					F[k].track = tracks[i];
					if( max < k ) max = k;
				}
			}
		}

		for( int i = N; i > 0; i-- )
		{
			if( !F[i].arrival ) continue;

			int sum = i;
			while( F[i].prev != -1 )
			{
				cout << F[i].track << " ";
				i = F[i].prev;
			}
			cout << "sum:" << sum << endl;
			break;
		}
	}
	return 0;
}
